import os
import sys
import sqlite3
from pathlib import Path

# 将项目根目录添加到Python路径
BASE_DIR = Path(__file__).resolve().parent.parent
sys.path.append(str(BASE_DIR))

# 获取数据库文件路径
db_path = BASE_DIR / 'db_new.sqlite3'

def main():
    # 连接数据库
    conn = sqlite3.connect(db_path)
    cursor = conn.cursor()

    try:
        # 查看所有表
        cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
        tables = cursor.fetchall()
        print("\nTables in database:")
        for table in tables:
            print(f"- {table[0]}")

        # 查看users表结构
        if ('users',) in tables:
            print("\nColumns in users table:")
            cursor.execute("PRAGMA table_info(users);")
            columns = cursor.fetchall()
            for col in columns:
                print(f"- {col[1]} ({col[2]})")
        else:
            print("\nWarning: users table does not exist!")

    except Exception as e:
        print(f"Error: {e}")
    finally:
        # 关闭连接
        conn.close()

if __name__ == '__main__':
    main()